package com.gy.assistant.ui.meeting;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.util.Locale;
import java.util.concurrent.TimeUnit;

import com.gy.assistant.R;
import com.gy.assistant.ui.BaseActivity;

public class MeetingEndedActivity extends BaseActivity {

    public static void actionStart(Activity activity, String callerID,long meetingDuration,long userDuration) {
        Intent intent = new Intent(activity, MeetingEndedActivity.class);
        intent.putExtra("caller",callerID);
        intent.putExtra("meetingDuration",meetingDuration);
        intent.putExtra("userDuration",userDuration);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meeting_ended);

        String caller = getIntent().getStringExtra("caller");
        long userDuration = getIntent().getLongExtra("userDuration",0);
        long meetingDuration = getIntent().getLongExtra("meetingDuration",0);
        TextView tv_title = findViewById(R.id.tv_title);
        Button btn_close = findViewById(R.id.btn_close);
        TextView tv_meeting_duration = findViewById(R.id.tv_meeting_duration);
        TextView tv_meeting_join_duration = findViewById(R.id.tv_meeting_join_duration);

        btn_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        tv_meeting_duration.setText(String.format("会议时长：%s",millSecondsFormat(meetingDuration)));
        tv_meeting_join_duration.setText(String.format("参会时长：%s",millSecondsFormat(userDuration)));

    }

    private String millSecondsFormat(long duration){

        long hour = TimeUnit.MILLISECONDS.toHours(duration);
        long minutes = TimeUnit.MILLISECONDS.toMinutes(duration);
        long seconds = TimeUnit.MILLISECONDS.toSeconds(duration);

        return String.format(Locale.getDefault(),"%02d:%02d:%02d",hour,minutes,seconds);
    }
}